#include <stdint.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <sys/types.h>
#include <androidfw/AssetManager.h>
#include <utils/threads.h>
#include <media/AudioSystem.h>
#include <media/mediaplayer.h>
#include <media/IMediaHTTPService.h>
#ifdef __cplusplus  
extern "C"{  
#endif  
using namespace android;
int playMusic(const char *path) {
    //sp<ProcessState> proc(ProcessState::self());
    //ProcessState::self()->startThreadpool();
    android::ProcessState::self()->startThreadPool();

    int index = 7;
    audio_devices_t adev;
    if(access(path, F_OK) == -1)
        return -1;
    sp<MediaPlayer> mp = new MediaPlayer();
    if (mp == NULL || path == NULL) {
        ALOGE("BootMusic: create MediaPlayer failed");
        return -1;
    }
    if (mp->setDataSource(NULL, path, NULL) == NO_ERROR) {
        mp->setAudioStreamType(AUDIO_STREAM_MUSIC);
        mp->prepare();
        mp->seekTo(0);
        //        mp->setVolume(1, 1);
        mp->start();
    } else {
        ALOGE("setDataSource err");
    }


    //IPCThreadState::self()->joinThreadPool();
    while (mp->isPlaying())
        sleep(1);

    mp->stop();
    mp->disconnect();
    return 0;
}

#ifdef __cplusplus  
}  
#endif 

